package com.love.marriage.userTransactionInfo.service.impl;

import com.love.marriage.userTransactionInfo.entity.UserTransactionInfo;
import com.love.marriage.userTransactionInfo.vo.UserTransactionInfoVo;
import com.love.marriage.userTransactionInfo.mapper.UserTransactionInfoMapper;
import com.love.marriage.userTransactionInfo.service.UserTransactionInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  用户消费记录表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-17 07:58:40
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class UserTransactionInfoServiceImp extends ServiceImpl<UserTransactionInfoMapper, UserTransactionInfo> implements UserTransactionInfoService {

    private final UserTransactionInfoMapper userTransactionInfoMapper;

    @Override
    public Page<UserTransactionInfoVo> getPage(Long pageNum, Long pageSize, UserTransactionInfoVo userTransactionInfoVo) {
        Page<UserTransactionInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return userTransactionInfoMapper.getPage(page, userTransactionInfoVo);
    }

    @Override
    public UserTransactionInfoVo queryUserTransactionInfo(Long id) {
        return userTransactionInfoMapper.queryUserTransactionInfo(id);
    }

    @Override
    public UserTransactionInfoVo addUserTransactionInfo(UserTransactionInfoVo userTransactionInfoVo) {
        UserTransactionInfo userTransactionInfo = new UserTransactionInfo();
        BeanUtils.copyProperties(userTransactionInfoVo, userTransactionInfo);
        userTransactionInfoMapper.insert(userTransactionInfo);
        UserTransactionInfoVo res = new UserTransactionInfoVo();
        BeanUtils.copyProperties(userTransactionInfo, res);
        return res;
    }

    @Override
    public UserTransactionInfoVo updateUserTransactionInfo(UserTransactionInfoVo userTransactionInfoVo) {
        UserTransactionInfo userTransactionInfo = new UserTransactionInfo();
        BeanUtils.copyProperties(userTransactionInfoVo, userTransactionInfo);
        userTransactionInfoMapper.updateById(userTransactionInfo);
        return userTransactionInfoVo;
    }

    @Override
    public Boolean deleteUserTransactionInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        userTransactionInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
